<template>
	<div class="container">
		<div class="footer">
		  <a href="https://beian.miit.gov.cn" class="beian-link" target="_blank">
		        <span class="beian-icon"></span>
		        冀ICP备2024093937号-1
		  </a>
		</div>
	  </div>
</template>

<script>
	export default {
		name: 'VerifyPage',
		data() {
			return {
				  verifyStatus: '0',
				  qrData: null,
				  scanTime: Date.now(),
				  errorMessage: ''
			}
		},
		computed: {
		    /* isExpired() {
		      if (!this.qrData) return false;
		      return Date.now() - this.qrData.timestamp > 60000;
		    },
		    timeRemaining() {
		      if (!this.qrData) return '--';
		      const remaining = Math.max(0, 60000 - (Date.now() - this.qrData.timestamp));
		      return `${Math.ceil(remaining / 1000)} 秒`;
		    } */
		  },
		  mounted() {
		    this.verifyQRCode();
			this.navigateToError(); 
		  },
		  methods: {
		    // 解析URL参数
		    parseUrlParams() {
		      const urlParams = new URLSearchParams(window.location.search);
		      return {
		        token: urlParams.get('token'),
		        time: urlParams.get('startTime'),
		        source: urlParams.get('source')
		      };
		    },
		    
		    // 验证二维码
		    async verifyQRCode() {
		      try {		        
		        // 1. 解析URL参数
		        const params = this.parseUrlParams();
		        // 2. 检查是否通过二维码访问
		        if (params.source !== 'qr') {
				  this.verifyStatus = '1';
		          this.errorMessage = '请通过扫描二维码访问';
		          return;
		        }
		        console.log('params.token========='+params.token)
		        // 3. 检查参数完整性
		        if (!params.token) {
		          this.verifyStatus = '1';
		          this.errorMessage = '缺少必要的验证参数';
		          return;
		        }
		        
		        // 4. 保存二维码数据
		        this.qrData = {
		          token: decodeURIComponent(params.token),
		          timestamp: parseInt(params.time)
		        };
		        
		        // 5. 检查二维码是否过期
		        const currentTime = Date.now();
				console.log('currentTime========='+currentTime)
				console.log('timestamp========='+this.qrData.timestamp)
		        const qrAge = currentTime - this.qrData.timestamp;
		        console.log('qrAge========='+qrAge)
		        if (qrAge > 5000) { // 1分钟 =60000 ,1秒 = 1000 
		          this.verifyStatus = '1';
		          /* this.errorMessage = `二维码已过期 ${Math.ceil(qrAge / 1000)} 秒`; */
				  this.errorMessage = '二维码已过期，请重新扫描';
		          return;
		        }
				uni.reLaunch({
				  url: '/pages/sign-in/sign-in'
				}); 
		        
		      } catch (error) {
		        this.verifyStatus = '1';
		        this.errorMessage = error.message || '验证过程出现异常';
		      } finally {
				//调整失败界面
				/* uni.navigateTo({
				  url: 'pages/sign-in-success/sign-in-success'
				}); */ 
		      }
		    },
			navigateToError(){
				if(this.verifyStatus == '1'){
					console.log('verifyStatus===============1')
					uni.reLaunch({
					  url: '/pages/sign-in-error/sign-in-error?msg='+this.errorMessage
					}); 
				} 
			}
		  }
	}
</script>

<style scoped>
.container {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.header {
  text-align: center;
  color: white;
  margin-bottom: 30px;
}

.header h1 {
  font-size: 28px;
  margin-bottom: 10px;
}

.header p {
  opacity: 0.9;
}

.content {
  flex: 1;
  background: white;
  border-radius: 20px;
  padding: 30px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.status-container {
  text-align: center;
  padding: 40px 0;
}

.result-container {
  text-align: center;
  padding: 20px 0;
}

.status-icon {
  font-size: 80px;
  margin-bottom: 20px;
}

.status-icon.success {
  color: #4CAF50;
  animation: successPulse 0.6s ease-in-out;
}

.status-icon.failure {
  color: #F44336;
}

.status-icon.expired {
  color: #FF9800;
}

.status-icon.pending {
  color: #2196F3;
}

@keyframes successPulse {
  0% { transform: scale(0.8); opacity: 0; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

.result-container h2 {
  margin: 15px 0;
  color: #333;
  font-size: 24px;
}

.result-container p {
  color: #666;
  margin-bottom: 30px;
  font-size: 16px;
}

.info-box {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 20px;
  margin: 20px 0;
  text-align: left;
}

.info-box h3 {
  margin-bottom: 15px;
  color: #333;
  border-bottom: 2px solid #e9ecef;
  padding-bottom: 10px;
}

.info-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px dashed #dee2e6;
}

.info-item:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.label {
  color: #666;
  font-weight: 500;
  flex-shrink: 0;
}

.value {
  color: #333;
  font-weight: bold;
  word-break: break-all;
  text-align: right;
  max-width: 60%;
}

.text-danger {
  color: #F44336 !important;
}

.action-buttons {
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.btn {
  padding: 15px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s;
}

.btn-success {
  background: linear-gradient(to right, #4CAF50, #45a049);
  color: white;
}

.btn-primary {
  background: linear-gradient(to right, #2196F3, #1976D2);
  color: white;
}

.btn-secondary {
  background: #f8f9fa;
  color: #666;
  border: 1px solid #dee2e6;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.loader {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #2196F3;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@media (max-width: 600px) {
  .container {
    padding: 10px;
  }
  
  .content {
    padding: 20px;
  }
  
  .header h1 {
    font-size: 24px;
  }
  
  .status-icon {
    font-size: 60px;
  }
  
  .info-item {
    flex-direction: column;
    gap: 5px;
  }
  
  .value {
    max-width: 100%;
    text-align: left;
  }
  /* 底部样式 */
  .footer {
    text-align: center;
    padding: 20px;
    color: #666;
    font-size: 12px;
    border-top: 1px solid #eee;
  }
}
</style>